package com.fixme4trade.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
public class Sell implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	//@GeneratedValue
	@SequenceGenerator( name = "SELL_ID", sequenceName = "SELL_SEQ", allocationSize = 1 )  
	@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "SELL_ID" )
	@Column(name="sell_id", nullable=false)
	private Long id;

	@ManyToOne
	@JoinColumn(name="product_id", nullable=false)
	private Product product;	

	@OneToOne(cascade = CascadeType.REFRESH, optional=false, fetch=FetchType.EAGER, orphanRemoval=false)
	@JoinColumn(name="customer_id", nullable=false)
	private Customer customer;

	@OneToOne(cascade = CascadeType.REFRESH, optional=true, fetch=FetchType.EAGER, orphanRemoval=false)
	@JoinColumn(name="payment_id", nullable=true)
	private Payment payment;
			
	@Temporal(TemporalType.TIMESTAMP)
	private Date sellTime;
	
	private int quantity;
		
	private double unitPrice;
	
	private double disccount;
	
	private double shipping;
	
	public Sell() {

	}

	public long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}	

	public Payment getPayment() {
		return payment;
	}

	public void setPayment(final Payment payment) {
		this.payment = payment;
	}
	
	public Date getSellTime() {
		return sellTime;
	}

	public void setSellTime(final Date sellTime) {
		this.sellTime = sellTime;
	}
	
	public Product getProduct() {
		return product;
	}

	public void setProduct(final Product product) {
		this.product = product;
	}
	
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(final Customer customer) {
		this.customer = customer;
	}
		
	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(final int quantity) {
		this.quantity = quantity;
	}

	public double getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(final double unitPrice) {
		this.unitPrice = unitPrice;
	}
	
	public double getTotal() {
		return this.quantity * this.unitPrice - this.disccount + this.shipping;
	}

	public double getDisccount() {
		return disccount;
	}

	public void setDisccount(final double disccount) {
		this.disccount = disccount;
	}

	public double getShipping() {
		return shipping;
	}

	public void setShipping(final double shipping) {
		this.shipping = shipping;
	}
}